<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    ul {
      display: flex;
      border-bottom: 2px solid #e01222;
      padding: 0 10px;
    }

    li {
      width: 100px;
      height: 50px;
      line-height: 50px;
      list-style: none;
      text-align: center;
    }

    li a {
      display: block;
      text-decoration: none;
      font-weight: bold;
      color: #333333;
    }

    li a.active {
      background-color: #e01222;
      color: #fff;
    }
  </style>
</head>

<body>
  <div id="app">
    <ul>
      <!-- 使用 v-for 指令遍历 list 数组，item 是数组中的每个元素，index 是当前元素的索引 -->
      <li v-for="(item,index) in list" :key="item.id" @click="activeIndex=index">
        <!-- 使用动态绑定的 class，当 index 等于 activeIndex 时，添加 active 类 -->
        <a :class="{active:index===activeIndex}" href="#">
          <!-- 显示 item 对象中的 name 属性的值 -->
          {{item.name}}
        </a>
      </li>
    </ul>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: "#app",
      data: {
        activeIndex: 0, //变量 高亮索引

        // 数组  列表数据
        list: [
          { id: 1, name: "京东秒杀" },
          { id: 2, name: "每日特价" },
          { id: 3, name: "品类秒杀" },
        ],
      },
    });
  </script>
</body>

</html>